package org.cfg;

import com.sojoys.artifact.build.data.base.BaseCfg;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.ToolCopy;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.ArrayUtils;
import com.sojoys.artifact.tools.SK_String;
import com.xiaoleilu.hutool.util.StrUtil;
import com.sojoys.artifact.constant.DataModelKeyEnum;
/**
 * 灵装随机属性
 */
public class EquipmentRandomCfg extends BaseCfg<EquipmentRandomCfg> {

	/**
	 * 数据库表名称
	 */
	public static final String TABLE_NAME = "equipment_random";
	/**
	 * 完整类名称
	 */
	public static final String CLASS_NAME = "org.cfg.EquipmentRandomCfg"; 
	/**
	 * 字段个数
	 */
	public static final int COLUMN_COUNT= 6;
	/**
	 * 数据库源字段注释
	 */
	public static final String[] SOURCE_COLUMN_REMARKS = new String[]{"","属性大类","权重","属性","属性类型","等级",};
	/**
	 * 数据库源字段名字
	 */
	public static final String[] SOURCE_COLUMN_NAMES = new String[]{"id","superType","weight","attribute","attrType","level",};
	/**
	 * 拼音字段名字
	 */
	public static final String[] PINGYING_COLUMN_NAMES = new String[]{"id","superType","weight","attribute","attrType","level",};
	/**
	 * HashCode字段名字
	 */
	public static final Integer[] HASHCODE_COLUMN_NAMES = new Integer[]{3355,-332841643,-791592328,13085340,554007755,102865796,};
	/**
	 * 字段基本类型
	 */
	public static final String[] COLUMN_BASICTYPES = new String[]{"int","int","int","int[]","int","int",};
	/**
	 * 字段引用类型
	 */
	public static final Class[] COLUMN_CLASSTYPES = new Class[]{Integer.class,Integer.class,Integer.class,int[].class,Integer.class,Integer.class,};
	
	/**
	 * id
	 */
	private int id;
	
	/**
	 * 属性大类
	 */
	private int superType;
	
	/**
	 * 权重
	 */
	private int weight;
	
	/**
	 * 属性
	 */
	private int[] attribute;
	
	/**
	 * 属性类型
	 */
	private int attrType;
	
	/**
	 * 等级
	 */
	private int level;
	
	
	
	public static EquipmentRandomCfg builder() {
		EquipmentRandomCfg equipmentRandomCfg = new EquipmentRandomCfg();
		return equipmentRandomCfg;
	}
	
	/**
	 * id
	 */
	public int getId() {
		return id;
	}
	
	/**
	 * 属性大类
	 */
	public int getSuperType() {
		return superType;
	}
	
	/**
	 * 权重
	 */
	public int getWeight() {
		return weight;
	}
	
	/**
	 * 属性
	 */
	public int[] getAttribute() {
		return attribute;
	}
	
	/**
	 * 属性类型
	 */
	public int getAttrType() {
		return attrType;
	}
	
	/**
	 * 等级
	 */
	public int getLevel() {
		return level;
	}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.superType;
        values[2] = this.weight;
        values[3] = this.attribute;
        values[4] = this.attrType;
        values[5] = this.level;
        return values;
	}
	
	protected EquipmentRandomCfg createColumeValues(Object[] vals) {
		this.id = (int)vals[0];
		this.superType = (int)vals[1];
		this.weight = (int)vals[2];
		this.attribute = (int[])vals[3];
		this.attrType = (int)vals[4];
		this.level = (int)vals[5];
		return this;
	}
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.superType);
        map.put(keys[2], this.weight);
        map.put(keys[3], this.attribute);
        map.put(keys[4], this.attrType);
        map.put(keys[5], this.level);
        return map;
    }
    
    protected EquipmentRandomCfg createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.superType = (int)map.get(keys[1]);
   		this.weight = (int)map.get(keys[2]);
   		this.attribute = (int[])map.get(keys[3]);
   		this.attrType = (int)map.get(keys[4]);
   		this.level = (int)map.get(keys[5]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.superType);
        obj.put(keys[2], this.weight);
        obj.put(keys[3], this.attribute);
        obj.put(keys[4], this.attrType);
        obj.put(keys[5], this.level);
        return obj;
    }
    
    protected EquipmentRandomCfg createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.superType = obj.getIntValue(keys[1]);
	    this.weight = obj.getIntValue(keys[2]);
		this.attribute = obj.getObject(keys[3],int[].class);
	    this.attrType = obj.getIntValue(keys[4]);
	    this.level = obj.getIntValue(keys[5]);
        return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeInt(this.superType);
	    byteBuf.writeInt(this.weight);
	    byteBuf.writeObject(this.attribute);
	    byteBuf.writeInt(this.attrType);
	    byteBuf.writeInt(this.level);
    }
	
	protected EquipmentRandomCfg readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.superType = byteBuf.readInt(null);
	    this.weight = byteBuf.readInt(null);
	    this.attribute = byteBuf.readIntArray(null);
	    this.attrType = byteBuf.readInt(null);
	    this.level = byteBuf.readInt(null);
	    return this;
	}
	
	public EquipmentRandomCfg deepCopy(){
		EquipmentRandomCfg equipmentRandomCfg = null;
		try {
			equipmentRandomCfg = (EquipmentRandomCfg) super.clone();
		    equipmentRandomCfg.attribute = ToolCopy.copyObject(this.attribute);
			return equipmentRandomCfg;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return equipmentRandomCfg;
	}
//自定义内容起始位置
//自定义内容结束位置
}
